//
//  settingView.m
//  Regatta Mapping
//
//  Created by Asif on 8/4/12.
//  Copyright (c) 2012 TopOfStack Software. All rights reserved.
//

#import "settingView.h"

@implementation settingView

@synthesize ipField, portField, vCont;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.ipField.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"IP"];
    self.portField.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"PORT"];
    
    [self setContentSizeForViewInPopover:CGSizeMake(320, 220)];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
    
    ////NSLog(@"view is disappearing");
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction)endIpFieldEditing
{
    [self.ipField resignFirstResponder];
}
-(IBAction)endPortFieldEditing
{
    [self.portField resignFirstResponder];
}


-(IBAction)setButtonPressed
{
    //NSLog(@"%@:%@", self.ipField.text, self.portField.text);
    
    [[NSUserDefaults standardUserDefaults] setObject:self.ipField.text forKey:@"IP"];
    [[NSUserDefaults standardUserDefaults] setObject:self.portField.text forKey:@"PORT"];
    
    //[vCont initNetWorkCommunication];
    
    [vCont initNetWorkCommunicationWithIP:self.ipField.text Port:[self.portField.text intValue]];
    
   
}


-(void) dealloc
{
    [vCont release];
    [portField release];
    [ipField release];
    [super dealloc];
}


@end
